def parse_atmtypenumbers(filename =None):
    atom_radii = {}
    patterns = []

    if not filename:
        filename = 'data/atmtypenumbers'
    lines = open(filename,'rb').readlines()
    for line in lines:
        if not line.strip() or line.startswith('#'):
            continue
        fields = line.split()

        if fields[0] == 'radius':
            n = int(fields[1])
            explicit_radius = float(fields[3])
            try:
                united_radius  = float(fields[4])
            except:
                united_radius = explicit_radius
            atom_radii[n] = (fields[2], explicit_radius, united_radius)

        else:
            residue_pattern = fields[0]
            if residue_pattern == '*':
                residue_pattern = '.*', #any residue
            atom_pattern = fields[1]
            atom_pattern = atom_pattern.replace('_', ', ') # 'CD__', -> 'CD  '
            atom_number = int(fields[2])

            patterns.append((residue_pattern, atom_pattern, atom_number))
            assert atom_number in atom_radii

    return (atom_radii, patterns)

#EOF